// TestIMUView.cpp : implementation file
//

#include "stdafx.h"
#include "GStation.h"
#include "TestIMUView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestIMUView

IMPLEMENT_DYNCREATE(CTestIMUView, CFormView)

CTestIMUView::CTestIMUView()
	: CFormView(CTestIMUView::IDD)
{
	//{{AFX_DATA_INIT(CTestIMUView)
	m_imu_v = _T("");
	//}}AFX_DATA_INIT
}

CTestIMUView::~CTestIMUView()
{
}

void CTestIMUView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestIMUView)
	DDX_Text(pDX, IDC_EDIT1, m_imu_v);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTestIMUView, CFormView)
	//{{AFX_MSG_MAP(CTestIMUView)
	ON_BN_CLICKED(IDC_StartImuTest, OnStartImuTest)
	ON_BN_CLICKED(IDC_StopImuTest, OnStopImuTest)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestIMUView diagnostics

#ifdef _DEBUG
void CTestIMUView::AssertValid() const
{
	CFormView::AssertValid();
}

void CTestIMUView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTestIMUView message handlers

CGStationDoc * CTestIMUView::GetDocument()
{
	return (CGStationDoc * )m_pDocument;
}

void CTestIMUView::OnStartImuTest() 
{
	// TODO: Add your control notification handler code here
	unsigned char * buf;
	buf = (unsigned char *)malloc(2);
	INSHEAD * head = (INSHEAD *)buf;
	*head  = TIT_IMUTEST_START;
	while(doc->cln.OnSendData(buf,2)==false)
	{

	}
	free(buf);
}

void CTestIMUView::OnStopImuTest() 
{
	// TODO: Add your control notification handler code here

	unsigned char * buf;
	buf = (unsigned char *)malloc(2);
	INSHEAD * head = (INSHEAD *)buf;
	*head  = TIT_IMUTEST_STOP;
	while(doc->cln.OnSendData(buf,2)==false){}
	free(buf);
}

void CTestIMUView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(doc->msg_IMUTestData_tag ==  true)
	{
		doc->msg_IMUTestData_tag = false;
		CString s;
		char c1 = '\r';
		char c2 = '\n';
		s.Format("IMUState %d %c%c",doc->msg_IMUTestData.IMUState,c1,c2);
		m_imu_v = s;
		s.Format("N_Speed %f %c%c",doc->msg_IMUTestData.p,c1,c2);
		m_imu_v += s;
		s.Format("E_Speed %f %c%c",doc->msg_IMUTestData.q,c1,c2);
		m_imu_v += s;
		s.Format("D_Speed %f %c%c",doc->msg_IMUTestData.r,c1,c2);
		m_imu_v += s;
		s.Format("N_Acc %f %c%c",doc->msg_IMUTestData.N_Acc,c1,c2);
		m_imu_v += s;
		s.Format("E_Acc %f %c%c",doc->msg_IMUTestData.E_Acc,c1,c2);
		m_imu_v += s;
		s.Format("D_Acc %f %c%c",doc->msg_IMUTestData.D_Acc,c1,c2);
		m_imu_v += s;
		s.Format("phi %f %c%c",doc->msg_IMUTestData.phi,c1,c2);
		m_imu_v += s;
		s.Format("theta %f %c%c",doc->msg_IMUTestData.theta,c1,c2);
		m_imu_v += s;
		s.Format("psi %f %c%c",doc->msg_IMUTestData.psi,c1,c2);
		m_imu_v += s;
	}
	UpdateData(false);
	
}
